//
//  DYGradientBtn.m
//  DYAutoLayoutGradientColor
//
//  Created by 黄德玉 on 2017/11/29.
//  Copyright © 2017年 none. All rights reserved.
//

#import "DYGradientBtn.h"

@interface DYGradientBtn()

@property (nonatomic,strong) CAGradientLayer * gradientLayer;

@end

@implementation DYGradientBtn


+ (Class)layerClass{
    return  [CAGradientLayer class];
}

+ (instancetype)buttonWithType:(UIButtonType)buttonType{
    DYGradientBtn * btn = [super buttonWithType:buttonType];
    btn.gradientLayer = (CAGradientLayer * )btn.layer;
    return btn;
}


- (instancetype)init{
    if (self = [super init]) {
        self.gradientLayer = (CAGradientLayer * )self.layer;
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.gradientLayer = (CAGradientLayer * )self.layer;
    }
    return self;
}




- (void)addGradientWithStartPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint colors:(NSArray *)colors locations:(NSArray *)locations{
    self.gradientLayer.startPoint = startPoint;
    self.gradientLayer.endPoint = endPoint;
    self.gradientLayer.colors = colors;
    self.gradientLayer.locations = locations;
}

- (void)addColors:(NSArray *)colors{
    self.gradientLayer.startPoint = CGPointMake(0, 0.5);
    self.gradientLayer.endPoint = CGPointMake(1, .5);
    self.gradientLayer.colors = colors;
}

@end
